package code.springboot.idempotent.keyresolver.impl;

import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.StrUtil;
import code.springboot.idempotent.annotation.Idempotent;
import code.springboot.idempotent.keyresolver.KeyResolver;
import org.aspectj.lang.JoinPoint;

/**
 * 默认的 key 解析器 根据方法名和参数生成 key
 * @author rocky
 * @date 2023/02/18
 */
public class DefaultIdempotentKeyResolver implements KeyResolver {

    @Override
    public String resolver(JoinPoint joinPoint, Idempotent idempotent) {
        String methodName = joinPoint.getSignature().toString();
        String argsStr = StrUtil.join(StrPool.COMMA, joinPoint.getArgs());
        return methodName + argsStr;
    }
}
